package springinpractice.r4_2.model;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Email;
import org.springmodules.validation.bean.conf.loader.annotation.handler.Expression;
import org.springmodules.validation.bean.conf.loader.annotation.handler.MaxLength;
import org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

public class User {
	
	@NotBlank
	@MaxLength(40)
	private String firstName;
	
	@NotBlank
	@MaxLength(40)
	private String lastName;
	
	@NotBlank
	@MaxLength(20)
	private String username;
	
	@NotBlank
	@MaxLength(80)
	@Email
	private String email;
	
	@NotBlank
	@MaxLength(20)
	@Expression(value = "password equals passwordConfirmation", 
			errorCode = "password.not.match")
	private String password;
	
	private String passwordConfirmation;
	
	private boolean marketingOk = true;
	
	@Expression(value = "acceptTerms equals true",
			errorCode = "terms.not.accepted")
	private boolean acceptTerms = false;
	
	private boolean enabled = true;
	
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
		
	public String getUsername() {
		return username;
	}	
	
	public void setUsername(String userName) {
		this.username = userName;
	}
		
	public String getEmail() {
		return email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getPassword() {
		return password;
	}	
	
	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordConfirmation() {
		return passwordConfirmation;
	}

	public void setPasswordConfirmation(String passwordConfirmation) {
		this.passwordConfirmation = passwordConfirmation;
	}
	
	public boolean isMarketingOk() {
		return marketingOk;
	}
	
	public void setMarketingOk(boolean marketingOk) {
		this.marketingOk = marketingOk;
	}
	
	public boolean getAcceptTerms() {
		return acceptTerms;
	}
	
	public void setAcceptTerms(boolean acceptTerms) {
		this.acceptTerms = acceptTerms;
	}
	
	public boolean isEnabled() {
		return enabled;
	}
	
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
			.append("firstName", firstName)
			.append("lastName", lastName)
			.append("userName", username)
			.append("email", email)
			.append("marketingOk", marketingOk)
			.append("acceptTerms", acceptTerms)
			.append("enabled", enabled)
			.toString();			
	}		
}
